﻿namespace FFF.Test
{
    using System;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using Abp.Application.Services;
    using Microsoft.AspNetCore.Authentication.JwtBearer;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Options;
    using Microsoft.IdentityModel.Tokens;
    using Senparc.CO2NET;
    using Senparc.CO2NET.RegisterServices;
    using Senparc.Weixin;
    using Senparc.Weixin.Entities;
    using Senparc.Weixin.MP;
    using Senparc.Weixin.RegisterServices;
    using Senparc.Weixin.TenPay;
    using Senparc.Weixin.WxOpen;
    using Swashbuckle.AspNetCore.Swagger;
    using Swashbuckle.AspNetCore.SwaggerGen;

    /// <summary>
    /// 配置文档生成
    /// </summary>
    public static class WxConfigurer
    {
        /// <summary>
        /// 配置文档生成
        /// </summary>
        /// <param name="services">程序的服务对象</param>
        /// <param name="configuration">程序的配置对象</param>
        /// <param name="env">环境节点</param>
        public static void ConfigureServices(IServiceCollection services, IConfiguration configuration, IHostingEnvironment env)
        {
            services.AddSenparcGlobalServices(configuration) //Senparc.CO2NET 全局注册
                    .AddSenparcWeixinServices(configuration); //Senparc.Weixin 注册

        }

        /// <summary>
        /// 文档的配置
        /// </summary>
        /// <param name="app">app环境</param>
        /// <param name="env">env的环境</param>
        /// <param name="senparcSetting">基础配置</param>
        /// <param name="senparcWeixinSetting">微信配置</param>
        public static void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
        {
            // 启动 CO2NET 全局注册，必须！
            IRegisterService register = RegisterService.Start(env, senparcSetting.Value)
                                                        .UseSenparcGlobal();
            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value)
                .RegisterMpAccount(senparcWeixinSetting.Value, "【于大明】公众号")
                .RegisterWxOpenAccount(senparcWeixinSetting.Value, "【于大明】小程序")
                .RegisterTenpayV3(senparcWeixinSetting.Value, "【于大明】公众号")
                .RegisterMpAccount("微信公众号APPId", "微信公众号密钥", "微信公众号");
        }
    }
}
